package com.ruoyi.project.system.sample.controller;

import java.util.List;

import com.ruoyi.project.system.device.domain.MyDeviceDTO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.sample.domain.MySample;
import com.ruoyi.project.system.sample.service.IMySampleService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 做样信息Controller
 * 
 * @author ruoyi
 * @date 2024-08-15
 */
@Controller
@RequestMapping("/system/sample")
public class MySampleController extends BaseController
{
    private String prefix = "system/sample";

    @Autowired
    private IMySampleService mySampleService;

    @RequiresPermissions("system:sample:view")
    @GetMapping()
    public String sample()
    {
        return prefix + "/sample";
    }

    /**
     * 查询做样信息列表
     */
    @RequiresPermissions("system:sample:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MySample mySample)
    {
        startPage();
        List<MySample> list = mySampleService.selectMySampleList(mySample);
        return getDataTable(list);
    }

    /**
     * 导出做样信息列表
     */
    @RequiresPermissions("system:sample:export")
    @Log(title = "做样信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MySample mySample)
    {
        List<MySample> list = mySampleService.selectMySampleList(mySample);
        ExcelUtil<MySample> util = new ExcelUtil<MySample>(MySample.class);
        return util.exportExcel(list, "做样信息数据");
    }

    /**
     * 新增做样信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存做样信息
     */
    @RequiresPermissions("system:sample:add")
    @Log(title = "做样信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MySample mySample)
    {
        return toAjax(mySampleService.insertMySample(mySample));
    }

    /**
     * 修改做样信息
     */
    @RequiresPermissions("system:sample:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MySample mySample = mySampleService.selectMySampleById(id);
        mmap.put("mySample", mySample);
        return prefix + "/edit";
    }

    /**
     * 修改做样信息
     */
    @GetMapping("/details/{id}")
    public String details(@PathVariable("id") Long id, ModelMap mmap)
    {
        MySample mySample = mySampleService.selectMySampleById(id);
        mmap.put("mySample", mySample);
        return prefix + "/data/edit";
    }
    /**
     * 修改保存做样信息
     */
    @RequiresPermissions("system:sample:edit")
    @Log(title = "做样信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MySample mySample)
    {
        return toAjax(mySampleService.updateMySample(mySample));
    }

    /**
     * 删除做样信息
     */
    @RequiresPermissions("system:sample:remove")
    @Log(title = "做样信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mySampleService.deleteMySampleByIds(ids));
    }

}
